package com.tledu.mr;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        // key 聚合过来的key
        // values 是这key的所有的值
        // 要求频率，计数
        int sum = 0;
        for (IntWritable val : values) {
            sum += val.get();
        }
        // 求出了综合
        context.write(key,new IntWritable(sum));
    }

}
